<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="backstage/css/pintuer.css">
<link rel="stylesheet" href="backstage/css/admin.css">
<script src="backstage/js/jquery.js"></script>
<script src="backstage/js/pintuer.js"></script>
</head>
<body>
<c:if test="${empty requestScope.article}">
	<c:redirect url="backstage/list.jsp"></c:redirect>
</c:if>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>修改内容</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="change.do" enctype="multipart/form-data">  
      <div class="form-group">
        <div class="label">
          <label>标题：</label>
        </div>
        <div class="field">
		  <input type="hidden" name="changeAid" id="" value="${article.aid}" />
          <input type="text" class="input w50" value="${article.title}" name="title" data-validate="required:请输入标题" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>图片：</label>
        </div>
        <div class="field">
		  <input type="hidden" name="oldImgPath" value="${article.img}" />
          <input type="text" id="url1" name="img" class="input tips" readonly style="width:25%; float:left;"  value=""  data-toggle="hover" data-place="right" data-image="${article.img}" />
          <input type="file" class="margin-left" name="file" id="image1" style="float:left;" accept=".jpg,.png">
        </div>
      </div>     
      
      <if condition="$iscid eq 1">
        <div class="form-group">
          <div class="label">
            <label>分类标题：</label>
          </div>
          <div class="field">
            <select name="type" class="input w50">
            <c:forEach var="type" items="${requestScope.myTypes}">
            	 <option value="${type.tid}">${type.tName}</option>
            </c:forEach>
            </select>
            <div class="tips"></div>
          </div>
        </div>
        
      </if>
      <div class="form-group">
        <div class="label">
          <label>描述：</label>
        </div>
        <div class="field">
          <textarea class="input" name="summary" style=" height:90px;">${article.summary}</textarea>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>内容：</label>
        </div>
        <div class="field">
          <textarea name="content" class="input" style="height:450px; border:1px solid #ddd;">${article.content}</textarea>
          <div class="tips"></div>
        </div>
      </div>
     
      <div class="clear"></div>
      <div class="form-group">
        <div class="label">
          <label>发布时间：</label>
        </div>
        <div class="field"> 
        <fmt:formatDate value="${article.createTime}" type="both" var="createtime"/>
          <input type="text" class="laydate-icon input w50" name="datetime" value="${createtime}"  data-validate="required:日期不能为空" readonly  style="padding:10px!important; height:auto!important;border:1px solid #ddd!important;" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>作者：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="author" value="${article.author}"  />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>点击次数：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="consult" value="${article.consult}" data-validate="member:只能为数字"  />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
		    <button class="button bg-main " type="button" onclick="history.back();">返回列表</button>
        </div>
      </div>
    </form>
	<!-- 评论区 -->
	<form method="post" action="" id="listform">
	  <div class="panel admin-panel">
	    <div class="panel-head"><strong class="icon-reorder">评论管理-评论列表</strong></div>    
	    <table class="table table-hover text-center">
	      <tr>
	        <th width="100" style="text-align:left; padding-left:20px;">编号</th>
	        <th width="30%">作者</th>
	        <th>IP地址</th>
	        <th width="10%">添加时间</th>       
	        <th>评论内容</th>
			<th>点赞数量</th>
	        <th width="310">操作</th>
	      </tr>
		  <c:if test="${empty comments}">
		  	<td colspan="7" align="center" style="color: palevioletred;">
				暂无评论
			</td>
		  </c:if>
	      <c:forEach var="item" items="${comments}">
	      	 <tr>
	          <td style="text-align:left; padding-left:20px;"><input type="checkbox" name="id[]" value="" />
	          ${item.cid}</td>
	          <td>${item.cauthor}</td>
	          <td>${item.cip}</td>		  
	          <td><fmt:formatDate value="${item.date}" type="both"/> </td>
	          <td>${item.content}</td>
		      <td>${item.likeNum}</td>
	          <td><div class="button-group"><a class="button border-red" href="javascript:void(0)" onclick="del(${item.cid})"><span class="icon-trash-o"></span> 删除</a> </div></td>
	        </tr>
	      </c:forEach>
	   				
	      <tr>
	        <td style="text-align:left; padding:19px 0;padding-left:20px;"><input type="checkbox" id="checkall"/>
	          全选 </td>
	        <td colspan="7" style="text-align:left;padding-left:20px;"> <a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" onclick="DelSelect()"> 批量删除</a> </td>
	      </tr>
		 
	    </table>
	  </div>
	</form>
	
  </div>
</div>
<script type="text/javascript">


//单个删除
function del(id){
	if(confirm("您确定要删除吗?")){
		$j.post("del.do","delCid="+id,function(e){
			if(e=="true")
			location.reload();
			else
			alert("删除失败");
		},"text")
	}
}

$j("input[name=file]").change(function(){
	var imgObj=this.files[0];
	if(imgObj!=undefined){
		var reader=new FileReader();
		reader.readAsDataURL(imgObj);
		reader.onload=function(){
			$j("#url1").attr({"data-image":reader.result});
			var myindex=$j("input[name=file]").val().lastIndexOf('\\')+1;
			$j("#url1").val($j("input[name=file]").val().substring(myindex));
			
		}
	}else{
		//点击取消还原
		$j("#url1").attr("data-image",'${article.img}');
		$j("#url1").val("");
	}
	
})

//全选
$j("#checkall").click(function(){ 
  $j("input[name='id[]']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

//批量删除
function DelSelect(){
	var Checkbox=false;
	 $j("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false;		
		$j("#listform").submit();		
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}



</script>
</body></html>